<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    const arr = [1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4]
    let result = arr.reduce((pre, cur) => {
        // if (pre.includes(cur)) {
        //     return pre
        // } else {
        //     return pre.concat(cur)
        // }

        // 第二种
        if(Array.isArray(pre)){
            pre.findIndex((item)=>{

            })
        }
    }, [])
    console.log("去重：", result)


    let count = {}

    let result2 = arr.reduce((pre, cur) => {
        if (cur in pre) {
            pre[cur]++
        } else {
            pre[cur] = 1
        }
        return pre
    }, {})
    console.log("统计次数:", result2)


    const arr2 = [1,[2],[3,4],[5,[6,[7,8,[9]]]]]
    let arr_new = (arr2) => arr2.reduce((pre,cur)=>{
       return  pre.concat(Array.isArray(cur) ? arr_new(cur) : cur)
    },[])
    console.log("扁平化：",arr_new(arr2))
</script>
</body>
</html>